package com.mlz.mlzmall.ui.activity.act.base;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mlz.mlzmall.R;

/**
 * @version 1.0
 * Created by 安帅 on 2016/05/23.
 * @description
 */

/***
 * 顶部的状态栏
 */
public class TopTitleView extends FrameLayout implements View.OnClickListener {

    public TextView mTxtLeft;
    public TextView mTxtRight;
    public TextView mTxtTitle;

    private LinearLayout mLinLeft = null;
    private LinearLayout mLinTitle = null;
    private LinearLayout mLinRight = null;

    private ImageView mImgLeft = null;
    private ImageView mImgRight = null;
    private ImageView mImgTitle = null;

    private OnLeftButtonClickListener mOnLeftButtonClickListener;
    private OnRightButtonClickListener mOnRightButtonClickListener;
    private OnTitleButtonClickListener mOnTitleButtonClickListener;

    /*
    设置Titile左边的内容
     */
    public void setLeftButtonContent(String text, Integer imageId, Integer backgroundImgId) {

        mLinLeft.setVisibility(View.VISIBLE);

        if (text != null) {
            mTxtLeft.setVisibility(View.VISIBLE);
            mTxtLeft.setText(text);
        } else {
            mTxtLeft.setVisibility(View.GONE);
        }

        if (imageId != null) {
            mImgLeft.setVisibility(View.VISIBLE);
            mImgLeft.setImageResource(imageId);
        } else {
            mImgLeft.setVisibility(View.GONE);
        }

        if (backgroundImgId != null) {
            mLinLeft.setBackgroundResource(backgroundImgId);
        }
    }

    /*
    设置Titile右边的内容
     */
    public void setRightButtonContent(String text, Integer imageId, Integer backgroundImgId) {

        mLinRight.setVisibility(View.VISIBLE);
        if (text != null) {
            mTxtRight.setVisibility(View.VISIBLE);
            mTxtRight.setText(text);
        } else {
            mTxtRight.setVisibility(View.GONE);
        }

        if (imageId != null) {
            mImgRight.setVisibility(View.VISIBLE);
            mImgRight.setImageResource(imageId);
        } else {
            mImgRight.setVisibility(View.GONE);
        }

        if (backgroundImgId != null) {
            mLinRight.setBackgroundResource(backgroundImgId);

        }
    }

    /*
   设置Titile中间的内容
    */
    public void setTitleButtonContent(String text, Integer imageId, Integer backgroundImgId) {

        mLinTitle.setVisibility(View.VISIBLE);
        if (text != null) {
            mTxtTitle.setVisibility(View.VISIBLE);
            mTxtTitle.setText(text);
        } else {
            mTxtTitle.setVisibility(View.GONE);
        }

        if (imageId != null) {
            mImgTitle.setVisibility(View.VISIBLE);
            mImgTitle.setImageResource(imageId);
        } else {
            mImgTitle.setVisibility(View.GONE);
        }

        if (backgroundImgId != null) {
            mLinTitle.setBackgroundResource(backgroundImgId);
        }
    }

    public void setOnLeftButtonClickListener(OnLeftButtonClickListener listener) {
        mOnLeftButtonClickListener = listener;
    }

    public void setOnRightButtonClickListener(OnRightButtonClickListener listener) {
        mOnRightButtonClickListener = listener;
    }


    public void setOnTitleButtonClickListener(OnTitleButtonClickListener listener) {
        mOnTitleButtonClickListener = listener;
    }

    public TopTitleView(Context context) {
        this(context, null);
    }

    public TopTitleView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TopTitleView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.top_title_view_layout, this, true);

        mLinLeft = (LinearLayout) findViewById(R.id.view_simple_title_lin_left);
        mLinRight = (LinearLayout) findViewById(R.id.view_simple_title_lin_right);
        mLinTitle = (LinearLayout) findViewById(R.id.view_simple_title_lin_title);

        mImgLeft = (ImageView) findViewById(R.id.view_simple_title_img_left);
        mImgRight = (ImageView) findViewById(R.id.view_simple_title_img_right);
        mImgTitle = (ImageView) findViewById(R.id.view_simple_title_img_title);

        mTxtLeft = (TextView) findViewById(R.id.view_simple_title_txt_left);
        mTxtRight = (TextView) findViewById(R.id.view_simple_title_txt_right);
        mTxtTitle = (TextView) findViewById(R.id.view_simple_title_txt_title);


        mLinLeft.setOnClickListener(this);
        mLinTitle.setOnClickListener(this);
        mLinRight.setOnClickListener(this);
    }

    /*
        public void setTitle(String text) {

            mTxtTitle.setVisibility(View.VISIBLE);
            mTxtTitle.setText(text);
        }

        public void setTitle(int stringID) {
            mTxtTitle.setVisibility(View.VISIBLE);
            mTxtTitle.setText(stringID);
        }

    */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.view_simple_title_lin_left:
                if (mOnLeftButtonClickListener != null)
                    mOnLeftButtonClickListener.onLeftBtnClick(v);
                break;
            case R.id.view_simple_title_lin_right:
                if (mOnRightButtonClickListener != null)
                    mOnRightButtonClickListener.onRightBtnClick(v);
                break;
            case R.id.view_simple_title_lin_title:
                if (mOnTitleButtonClickListener != null)
                    mOnTitleButtonClickListener.onTitleBtnClick(v);
                break;
        }
    }

    public interface OnLeftButtonClickListener {
        public void onLeftBtnClick(View button);
    }

    public interface OnRightButtonClickListener {
        public void onRightBtnClick(View button);
    }


    public interface OnTitleButtonClickListener {
        public void onTitleBtnClick(View button);
    }
}
